package com.xuelang.pipeline.artifact.entry.nexus3v1;

import com.xuelang.pipeline.artifact.app.nexus3v1.RepositoryManagementService;
import com.xuelang.pipeline.artifact.app.nexus3v1.request.*;
import com.xuelang.pipeline.artifact.app.nexus3v1.response.ListRepositoryResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * Nexus3V1 仓库管理原生接口web服务
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@RestController
@RequestMapping(value = "/repository/management", headers = "Accept=application/json")
public class RepositoryManagementController {

    @Autowired
    RepositoryManagementService repositoryManagementService;
    /**
     * 查询仓库列表
     *
     * @return
     */
    @GetMapping(value = "/list", produces = "application/json;charset=utf-8")
    ApiResponseXO<List<ListRepositoryResponse>> repositoryList() {
        return repositoryManagementService.listRepository();
    }

    /**
     * 删除任意格式的仓库
     *
     * @param repositoryName
     * @return
     */
    @DeleteMapping(value = "/{repositoryName}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteRepositoryOfAnyFormat(@PathVariable("repositoryName") String repositoryName) {
        return repositoryManagementService.deleteRepositoryOfAnyFormat(repositoryName);
    }

    /**
     * 创建Maven-group仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/maven/group", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createMavenGroupRepository(@RequestBody @Valid CreateMavenGroupRequest request) {
        return repositoryManagementService.createMavenGroupRepository(request);
    }

    /**
     * 创建Maven-hosted仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/maven/hosted", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createMavenHostedRepository(@RequestBody @Valid CreateMavenHostedRequest request) {
        return repositoryManagementService.createMavenHostedRepository(request);
    }

    /**
     * 创建Maven-proxy仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/maven/proxy", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createMavenProxyRepository(@RequestBody @Valid CreateMavenProxyRequest request) {
        return repositoryManagementService.createMavenProxyRepository(request);
    }

    /**
     * 创建Npm-group仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/npm/group", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createNpmGroupRepository(@RequestBody @Valid CreateNpmGroupRequest request) {
        return repositoryManagementService.createNpmGroupRepository(request);
    }

    /**
     * 创建Npm-hosted仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/npm/hosted", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createNpmHostedRepository(@RequestBody @Valid CreateNpmHostedRequest request) {
        return repositoryManagementService.createNpmHostedRepository(request);
    }

    /**
     * 创建Npm-proxy仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/npm/proxy", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createNpmProxyRepository(@RequestBody @Valid CreateNpmProxyRequest request) {
        return repositoryManagementService.createNpmProxyRepository(request);
    }

    /**
     * 创建Docker-group仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/docker/group", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createDockerGroupRepository(@RequestBody @Valid CreateDockerGroupRequest request) {
        return repositoryManagementService.createDockerGroupRepository(request);
    }

    /**
     * 创建Docker-hosted仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/docker/hosted", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createDockerHostedRepository(@RequestBody @Valid CreateDockerHostedRequest request) {
        return repositoryManagementService.createDockerHostedRepository(request);
    }

    /**
     * 创建Docker-proxy仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/docker/proxy", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createDockerProxyRepository(@RequestBody @Valid CreateDockerProxyRequest request) {
        return repositoryManagementService.createDockerProxyRepository(request);
    }

    /**
     * 创建Raw-group仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/raw/group", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createRawGroupRepository(@RequestBody @Valid CreateRawGroupRequest request) {
        return repositoryManagementService.createRawGroupRepository(request);
    }

    /**
     * 创建Raw-hosted仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/raw/hosted", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createRawHostedRepository(@RequestBody @Valid CreateRawHostedRequest request) {
        return repositoryManagementService.createRawHostedRepository(request);
    }

    /**
     * 创建Raw-proxy仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/raw/proxy", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createRawProxyRepository(@RequestBody @Valid CreateRawProxyRequest request) {
        return repositoryManagementService.createRawProxyRepository(request);
    }
}
